<%@ Page Language="C#" %>
<script runat="server">
    private const string NoPic = "/Images/no_pic.gif";
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (Page.User.Identity.Name == "")
        {
            Response.End();
        }
    }

    protected string GetNickName()
    {
    	string tmp = "";
        using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["www_user.user"].ConnectionString))
        {
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select NickName from t_user where memberno='" + Page.User.Identity.Name + "'", conn);
            conn.Open();
            System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                tmp = dr[0].ToString();
                break;
            }
            dr.Close();
            conn.Close();
        }
        return tmp;
    }

    protected string GetAvatar()
    {
    	string Avatar = NoPic;
        using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["www_user.user"].ConnectionString))
        {
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select Avatar from t_user where memberno='" + Page.User.Identity.Name + "'", conn);
            conn.Open();
            System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Avatar = dr[0].ToString();
                Avatar = (Avatar.Trim() == "" ? NoPic : Avatar);
                break;
            }
            dr.Close();
            conn.Close();
        }
        return Avatar;
    }
</script>
<%
	/*
	 *	You need to set these variables to be appropriate for your site and user.
	 */
  String strFlashcomServer = "flashcom.italki.userplane.com";
  String strDomainID = "italki.com";
  String strSessionGUID = Page.User.Identity.Name;		// The session identifier for the currently logged in user
  String strKey = GetNickName();						// Additional login information you may need passed
  String strInitialRoom = Request.QueryString["InitialRoom"];				// Optional room name of the room the user will start in.  This overrides the similar setting in the XML
%>

<html>
<head>
	<meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
	<title>Userplane AV Webchat</title>

	<script language="JavaScript">
	<!--
		function csEvent( strEvent, strParameter1, strParameter2 )
		{
			if( strEvent == "InstantCommunicator.StartConversation" )
			{
				var strUserID = strParameter1;
				var bServer = strParameter2;
				// open up an InstantCommunicator window.  For example:
				launchWM( "<%= strSessionGUID %>", strUserID );
			}
			else if( strEvent == "User.ViewProfile" )
			{
				var strUserID = strParameter1;
				var tmp = "T";
				for(var i=0;i<9-strUserID.length;i++)
				{
				    tmp +="0";
				}
				strUserID = tmp + strUserID;
				window.open("/public/Profile.htm?memberno="+strUserID);
			}
			else if( strEvent == "User.Block" )
			{
				var strBlockedUserID = strParameter1;
				var bBlocked = strParameter2;
			}
			else if( strEvent == "User.AddFriend" )
			{
				var strFriendUserID = strParameter1;
				var bFriend = strParameter2;
			}
			else if( strEvent == "Chat.Help" )
			{
			}
			else if( strEvent == "User.NoTextEntry" )
			{
			}
			else if( strEvent == "Connection.Success" )
			{
			}
			else if( strEvent == "Connection.Failure" )
			{
				if( strParameter1 == "Session.Timeout" )
				{
					//handle timeout here, both inactivity and session timeouts
				}
				if( strParameter1 == "User.Banned" )
				{
					//handle ban event here
				}
			}
		}

		function launchWM( userID, destinationUserID )
		{
			var popupWindowTest = window.open( "wm_ads.aspx?strDestinationUserID=" + destinationUserID, "WMWindow_" + replaceAlpha(userID) + "_" + replaceAlpha(destinationUserID), "width=360,height=540,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
			if( popupWindowTest == null )
			{
				alert( "Your popup blocker stopped an IM window from opening" );
			}
		}

		function replaceAlpha( strIn )
		{
			var strOut = "";
			for( var i = 0 ; i < strIn.length ; i++ )
			{
				var cChar = strIn.charAt(i);
				if( ( cChar >= 'A' && cChar <= 'Z' )
					|| ( cChar >= 'a' && cChar <= 'z' )
					|| ( cChar >= '0' && cChar <= '9' ) )
				{
					strOut += cChar;
				}
				else
				{
					strOut += "_";
				}
			}

			return strOut;
		}
	//-->
	</script>
</head>
<body bgcolor="#ffffff" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0">






<%
	// Do not change anything below here
	String strSwfServer = "swf.userplane.com";
	String strApplicationName = "CommunicationSuite";
	String strLocale = "english";
%>

<script type="text/javascript" src="flashobject.js"></script>

<%
//	The content of this div should hold whatever HTML you would like to show in the case that the
//	user does not have Flash installed.  Its contents get replaced with the Flash movie for everyone
//	else.
%>
<div id="flashcontent">
	<strong>You need to upgrade your Flash Player by clicking <a href="http://www.macromedia.com/go/getflash/" target="_blank">this link</a>.</strong><br><br><strong>If you see this and have already upgraded we suggest you follow <a href="http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_14157" target="_blank">this link</a> to uninstall Flash and reinstall again.</strong>
</div>

<script type="text/javascript">
	// <![CDATA[

	var fo = new FlashObject("http://<%= strSwfServer %>/<%= strApplicationName %>/ch.swf", "ch", "100%", "100%", "6", "#ffffff", false, "best");
	fo.addParam("scale", "noscale");
	fo.addParam("menu", "false");
	fo.addParam("salign", "LT");
	fo.addParam("allowScriptAccess", "always");
	fo.addVariable("strServer", "<%= strFlashcomServer %>");
	fo.addVariable("strSwfServer", "<%= strSwfServer %>");
	fo.addVariable("strApplicationName", "<%= strApplicationName %>");
	fo.addVariable("strDomainID", "<%= strDomainID %>");
	fo.addVariable("strInstanceID", "");
	fo.addVariable("strSessionGUID", "<%= strSessionGUID %>");
	fo.addVariable("strKey", "<%= strKey %>");
	fo.addVariable("strLocale", "<%= strLocale %>");
	fo.addVariable("strInitialRoom", "<%= strInitialRoom %>");
	fo.write("flashcontent");

	// COPYRIGHT Userplane 2006 (http://www.userplane.com)
	// CS version 2.0.2

	// ]]>
</script>

</body>
</html>